//
//  TriangleMode.m
//  dataGathering
//
//  Created by apple on 14/12/23.
//  Copyright (c) 2014年 shuili. All rights reserved.
//

#import "TriangleMode.h"

@interface TriangleMode ()

@end

@implementation TriangleMode

-(instancetype)initWithMapview :(AGSMapView*)mapview
{
    return [super initWithMapview:mapview];
}

-(void)mapView:(AGSMapView *)mapView didClickAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features
{

    if([self.myPolygon numPoints] == 0){
        [self.myPolygon addPointToRing:mappoint];
        
        self.myGraphic = [[AGSGraphic alloc] initWithGeometry:self.myPolygon symbol:self.innerSymbol attributes:nil];
        [self.myGraphicsLayer addGraphic:self.myGraphic];
    } else if([self.myPolygon numPoints] == 1){

        [self.myPolygon addPointToRing:mappoint];
        
        self.myGraphic.geometry = self.myPolygon;
        
    } else if([self.myPolygon numPoints] == 2){
        [self.myPolygon addPointToRing:mappoint];
        [self.myPolygon closePolygon];
        
        self.myGraphic.geometry = self.myPolygon;
        
        //[self stop];
        
        //if (self.delegate && [self.delegate respondsToSelector:@selector(BaseMode:didFinishDrawing::)]) {
           // [self.delegate BaseMode:self didFinishDrawing:self.myPolygon :@"POLYGON"];
        //}
    } else {
        if([[AGSGeometryEngine defaultGeometryEngine] geometry:mappoint intersectsGeometry:self.myPolygon])
        {
            [self stop];
            
            if (self.delegate && [self.delegate respondsToSelector:@selector(BaseMode:didFinishDrawing::)]) {
                [self.delegate BaseMode:self didFinishDrawing:self.myPolygon :@"POLYGON"];
            }
        } else {
            for(int x=0;x<3;x++)
            {
                [self.myPolygon removePointOnRing:0 atIndex:0];
            }
            
            self.myGraphic.geometry = self.myPolygon;
        }
    }
}

@end
